home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Art
/
I
/
Imagic.cpt
/
External Functions
/
Grid Source
/
myFunction.c
< prev
next >
Wrap
Text File
|
1992-03-29
|
6KB
|
239 lines
/**************************************************************************************************
* myFunctions.c
*
* This is the file where you (the programmer) will put your code. The three functions
* below are the skeletal parts of what you must fill in. Just enter your code into each
* corresponding function, compile, and link with the ImagicXFunction Library. Then, you
* are done.
*
* See Documentation for further help. All of your answers should be answered there.
*
* For more complex and technical questions that the documentation could not answer,
* contact me, Brian Powell:
*
* (E-Mail is the best way. Preferably Internet)
* Internet : powellb@boulder.colorado.edu
* AppleLink: d3706
*
* (If you have no other means...)
* Brian Powell
* Colorado Center for Astrodynamics Research
* University of Colorado at Boulder
* Campus Box 431
* Boulder, CO 80309
* (303) 492-6677
*************************************************************************************************/
#include "XFunctions.h"
#include <math.h>
#include <Dialogs.h>
/* Declare any functions you may create here.
*/
void AddGrid();
/* Definitions
*/
enum {
OK_BUTTON = 1,
CANCEL_BUTTON,
XSCALE,
YSCALE,
PIXEL,
DEGREE
};
#define GRID_DIALOG 128
/* This is called whenever Imagic is beginning. You set up your parameters here. If there is
* anything you want to initialize, do that here.
*/
pascal OSErr Initialize(theParameters)
InitStruct *theParameters;
{
OSErr theError = noErr;
/* Insert Your Parameters Here. If these parameters are fine with you, leave them,
* otherwise set them up for your own needs. This is also the default settings, so don't
* change it unless you need to.
*/
theParameters->Filter = FALSE;
theParameters->NumOfImages = 1;
/* Make sure that we are not goint to crash Imagic on startup with wrong calls.
*/
if (GetVersion() < EXTERNAL_FUNCTION_LIBRARY_VERSION_NUM)
return (theError);
/* Insert your initialization code here.
*/
/* Let's go back to Imagic, giving it the parameters for our external module. */
return (theError);
}
/* This function is called whenever the user selects your command from the menu. This is the
* heart of your function.
*/
pascal OSErr ExecuteMenu()
{
OSErr theError=noErr;
DialogPtr theDialog; /* Dialog for asking the user how to space the grid. */
int item; /* Item selected by the user. */
ControlHandle pixelHandle, degreeHandle, xHandle, yHandle; /* Controls. */
int type;
Rect box;
long xscale, yscale; /* Values of the grid spacing. */
GrafPtr oldPort; /* Store the old Graf Port. */
Boolean pixelMode = TRUE; /* Default to use units of pixels. */
char string[256]; /* String to hold the values. */
/* Load the dialog, if there's an error, give it back to Imagic.
*/
theDialog = GetNewDialog(GRID_DIALOG, NIL, (WindowPtr)-1L);
if (theError = ResError()) return (theError);
GetPort(&oldPort);
SetPort(theDialog);
/* Get the dialog items.
*/
GetDItem(theDialog, XSCALE, &type, &xHandle, &box);
GetDItem(theDialog, YSCALE, &type, &yHandle, &box);
GetDItem(theDialog, PIXEL, &type, &pixelHandle, &box);
GetDItem(theDialog, DEGREE, &type, °reeHandle, &box);
/* Set the radio button, and select the text.
*/
SelIText(theDialog, XSCALE, 0, 32767);
SetCtlValue(pixelHandle, TRUE);
SetCtlValue(degreeHandle, FALSE);
/* Loop through getting the Dialog events.
*/
while (TRUE) {
/* Highlight the ok button.
*/
OutlineButton(theDialog, OK_BUTTON);
ModalDialog(TextFilter, &item);
switch (item) {
case OK_BUTTON:
GetIText(xHandle, (StringPtr)string);
StringToNum((StringPtr)string, &xscale);
GetIText(yHandle, (StringPtr)string);
StringToNum((StringPtr)string, &yscale);
DisposDialog(theDialog);
SetPort(oldPort);
AddGrid((int)xscale, (int)yscale, pixelMode);
return (theError);
break;
case CANCEL_BUTTON:
DisposDialog(theDialog);
SetPort(oldPort);
return (theError);
break;
case PIXEL:
pixelMode = TRUE;
SetCtlValue(pixelHandle, TRUE);
SetCtlValue(degreeHandle, FALSE);
break;
case DEGREE:
pixelMode = FALSE;
SetCtlValue(pixelHandle, FALSE);
SetCtlValue(degreeHandle, TRUE);
break;
default:
break;
}
}
/* Bye
*/
return (theError);
}
/* This function is called whenever Imagic quits. If you need to clear anything up
* before it quits, do so here.
*/
pascal OSErr Exit()
{
OSErr theError = noErr;
/* Insert your shut-down code here. Deallocate anything you may have left around, Do
* anything you may need to do as Imagic is quitting.
*/
/* Let's let Imagic quit, returning an error that may have occured.
*/
return (theError);
}
void AddGrid(x, y, pixelMode)
int x, y;
Boolean pixelMode;
{
ImageHandle image;
double thex, they;
int i, newx, newy;
int xsize, ysize;
Point topleft, botright;
short proj;
/* Get the top image. Make sure that we get one.
*/
if ((image = GetTopImage())==NIL)
return;
/* Okay, let's go through and draw it. We must make sure that we can work on it.
* Also, we'll set up for Undo, in case the user doesn't like it.
*/
GetImageSize(image, &xsize, &ysize);
if (BeginImageWork(image, TRUE)) {
/* If it's a straight pixel method, no problem.
*/
if (pixelMode) {
/* Go through and do the vertical lines.
*/
for (i=x; i<xsize; i+=x) {
MoveTo(i,0);
LineTo(i,ysize);
}
/* Now, do the horizontal lines.
*/
for (i=y; i<ysize; i+=y) {
MoveTo(0,i);
LineTo(xsize, i);
}
}
/* Otherwise, it is degree mode, which means we have to convert to pixels.
*/
else {
GetImageGeography(image, &topleft, &botright, &proj);
thex=(double)(x+topleft.h);
they=(double)(y+topleft.v);
do {
LatLonToPix(image, thex, they, &newx, &newy);
MoveTo(newx, 0);
LineTo(newx, ysize);
thex+=(double)x;
} while (newx<xsize);
thex=(double)x;
they=(double)y;
do {
LatLonToPix(image, thex, they, &newx, &newy);
MoveTo(0, newy);
LineTo(xsize, newy);
they+=(double)y;
} while (newy<ysize);
}
}
/* Finish up with the image.
*/
EndImageWork(image);
}